package com.supermap.database.ipfs;

import com.alibaba.fastjson.JSONObject;

import java.util.UUID;

/**
 * @author liqs
 * @version 1.0
 * @date 2020/5/11 11:30
 * 实现 IPFS 的并发测试
 */
public class IpfsThread extends Thread {

    private IpfsClient ipfsClient;
    private int testCount;

    /**
     * @param ipfsClient  ipfs客户端
     * @param testCount   测试次数
     */
    public IpfsThread(IpfsClient ipfsClient, int testCount){
        this.ipfsClient = ipfsClient;
        this.testCount = testCount;
    }

    @Override
    public void run() {
        // 说明 这里生成简单的字符串字节（36）是不耗时的，可以忽略，所以主要的时间来自于 IPFS
//        byte[] bytes = "5d513006-5cbd-4fa9-8f0d-937aea9fd29D".getBytes();
        for(int i = 0; i < testCount; i ++) {
            byte[] bytes = UUID.randomUUID().toString().getBytes();
            ipfsClient.upBytes(bytes);
//            System.out.println(jsonObject.getString("Hash"));
            // 读取
//        byte[] bytes = ipfsClient.downloadBytes("QmV3QqwsBwAAsVPrSuPKfD1Dorxf1twzGNi9XC9JRMzZkL");
        }
    }


}
